import { computed, Ref, ref } from "vue"
import { WeiboHot } from "../type/entity"

export function useSortFlag(){
  const firstTimeSort = ref(1)
  const topRankSort = ref(1)
  const timesSort = ref(1)
  return {
    firstTimeSort: firstTimeSort,
    topRankSort: topRankSort,
    timesSort
  }
}
export function useSearchOption(){
  const searchMethod = ref("byWord")
  const hotWord = ref("")
  const timeRange = ref<[Date, Date]>([
    new Date(),
    new Date(),
  ])
  const shortcuts = [
    {
      text: '最近6小时',
      value: () => {
        const end = new Date()
        const start = new Date()
        start.setTime(start.getTime() - 3600 * 1000 * 6)
        return [start, end]
      },
    },
    {
      text: '最近12小时',
      value: () => {
        const end = new Date()
        const start = new Date()
        start.setTime(start.getTime() - 3600 * 1000 * 12)
        return [start, end]
      },
    },
    {
      text: '最近一天',
      value: () => {
        const end = new Date()
        const start = new Date()
        start.setTime(start.getTime() - 3600 * 1000 * 24)
        return [start, end]
      },
    },
    {
      text: '最近三天',
      value: () => {
        const end = new Date()
        const start = new Date()
        start.setTime(start.getTime() - 3600 * 1000 * 24 * 3)
        return [start, end]
      },
    },
    {
      text: '最近一周',
      value: () => {
        const end = new Date()
        const start = new Date()
        start.setTime(start.getTime() - 3600 * 1000 * 24 * 7)
        return [start, end]
      },
    },
  ]
  return{
    searchMethod,
    hotWord,
    timeRange,
    shortcuts,
  }
}

export function usePagination(arr:Ref<any[]>){
  const total = computed(() => arr.value.length) //总条目数
  const pagerCount = ref(21) //最大页码按钮数
  const pageSize = ref(12) //每页展示的条目数
  const currentPage = ref(1) 
  return {
    total,
    pagerCount,
    pageSize,
    currentPage
  }
}